package ibmetp.mis.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.ResourceBundle;
/**
 * 数据库连接工具
 * @author LAN DABIN
 * @created 2011-9-30
 *
 */
public class DBUtil {
	
    private static final  String DRIVER="driver";//数据驱动
    private static final  String URL="url";//数据库位置
    private static final  String NAME="name";//用户名
    private static final  String PASSWORD="password";//密码
//	private static HashMap<K, V>
	/**
	 * 
	 * @return 返回连接
	 */
	public static Connection getConnection()
	{  
		Connection conn = null;
		try
		{  
//			if(conn!=null && !conn.isClosed())
//			{
//				return conn;
//			}
			ResourceBundle rb=ResourceBundle.getBundle("ibmetp/mis/config/database");
			String driverString=rb.getString(DRIVER);
			String urlString=rb.getString(URL);
			String nameString=rb.getString(NAME);
			String passwordString=rb.getString(PASSWORD);		
			Class.forName(driverString);
			conn=DriverManager.getConnection(urlString, nameString,passwordString);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return null;
		}
		return conn;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DBUtil.getConnection();

	}


}
